package com.micro.school.system.service.impl;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.system.domain.BannerResult;
import com.micro.school.system.mapper.BannerResultMapper;
import com.micro.school.system.service.BannerResultService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.List;


/**
 * (BannerResult)表服务实现类
 *
 * @author makejava
 * @since 2025-08-08 19:07:23
 */
@Service("BannerResultServiceImpl")
public class BannerResultServiceImpl implements BannerResultService {
    @Resource
    private BannerResultMapper bannerResultMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BannerResult queryById(Integer id) {
        return this.bannerResultMapper.queryById(id, SecurityContextHolder.getUserTenantId());
    }

    /**
     * 分页查询
     *
     * @param bannerResult 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public List<BannerResult> queryByPage(BannerResult bannerResult) {
        bannerResult.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        return this.bannerResultMapper.queryAllByLimit(bannerResult);
    }

    /**
     * 新增数据
     *
     * @param bannerResult 实例对象
     * @return 实例对象
     */
    @Override
    public BannerResult insert(BannerResult bannerResult) {
        bannerResult.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        this.bannerResultMapper.insert(bannerResult);
        return bannerResult;
    }

    /**
     * 修改数据
     *
     * @param bannerResult 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(BannerResult bannerResult) {
        bannerResult.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        return this.bannerResultMapper.update(bannerResult) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bannerResultMapper.deleteById(id, SecurityContextHolder.getUserTenantId()) > 0;
    }
}
